home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / MPW C++ / MPW C++ 3.1 / Examples / CPlusExamples / TApplication.h < prev    next >
Text File  |  1990-09-11  |  5KB  |  131 lines

  1. /*------------------------------------------------------------------------------
  2. #
  3. #    Apple Macintosh Developer Technical Support
  4. #
  5. #    MultiFinder-Aware Simple Application Framework
  6. #
  7. #    CPlusAppLib
  8. #
  9. #    TApplication.h    -    C++ source
  10. #
  11. #    Copyright © 1989 Apple Computer, Inc.
  12. #    All rights reserved.
  13. #
  14. #    Versions:    
  15. #            1.10                     07/89
  16. #            1.00                     04/89
  17. #
  18. #    Components:
  19. #            TApplicationCommon.h    July 9, 1989
  20. #            TApplication.h            July 9, 1989
  21. #            TDocument.h                July 9, 1989
  22. #            TApplication.cp            July 9, 1989
  23. #            TDocument.cp            July 9, 1989
  24. #            TApplication.r            July 9, 1989
  25. #
  26. #    CPlusAppLib is a rudimentary application framework
  27. #    for C++. The applications CPlusShapesApp and CPlusTESample
  28. #    are built using CPlusAppLib.
  29. #
  30. ------------------------------------------------------------------------------*/
  31.  
  32. #ifndef TAPPLICATION_H
  33. #define TAPPLICATION_H
  34.  
  35. // Include necessary interface files
  36. #include <Types.h>
  37. #include <Desk.h>
  38. #include <Events.h>
  39. #include <OSUtils.h>
  40.  
  41. // we need resource ids
  42. #include "TApplicationCommon.h"
  43.  
  44. // we need definitions of DocumentList class
  45. #include "TDocument.h"
  46.  
  47. /*
  48.     TApplication:
  49.  
  50.     This is our class which implements a basic Macintosh style program,
  51.     including a MultiFinder-aware event loop. 
  52. */
  53.  
  54. // we derive from handle object to prevent fragmentation
  55. class TApplication : HandleObject {
  56. public:
  57.     // Our constructor & destructor
  58.     TApplication(void);
  59.  
  60.     // Call this routine to start event loop running
  61.     void EventLoop(void);
  62.  
  63.     // Utility routines you can use
  64.     Boolean TrapAvailable(short tNumber,TrapType tType);    // Is trap implemented???
  65.     inline TDocumentList* DocList(void) { return fDocList; }
  66.  
  67. protected:
  68.     // Returns total stack space required in bytes.
  69.     // Returns 0 by default, which tells the initialization code
  70.     // to use the default stack size.
  71.     virtual long StackNeeded(void) { return 0; }
  72.     // Returns total heap space required in bytes.
  73.     // Returns 0 by default, which tells the initialization code
  74.     // to use whatever heap size is given.
  75.     virtual long HeapNeeded(void) { return 0; }
  76.  
  77.     // Loop control methods you may need to override
  78.     virtual void SetUp(void) {}                    // Run before event loop starts
  79.     virtual void CleanUp(void) {}                // run at end of loop
  80.     virtual void ExitLoop(void);                // to end loop, call this routine
  81.     virtual void DoIdle(void) {}                // idle time handler (blink caret, background tasks)
  82.     virtual void AdjustMenus(void) {}            // menu updater routine
  83.  
  84.     // event handlers you shouldn't need to override in a typical application
  85.     virtual void DoOSEvent(void);                // Calls DoSuspend, DoResume and DoIdle as apropos
  86.     virtual void DoMouseDown(void);                // Calls DoContent, DoGrow, DoZoom, etc
  87.     virtual void DoKeyDown(void);                // also called for autokey events
  88.     virtual void DoActivateEvt(void);            // handles setup, and calls DoActivate (below)
  89.     virtual void DoUpdateEvt(void);                // handles setup, and calls DoUpdate (below)
  90.     virtual void DoMouseInSysWindow(void) { SystemClick(&fTheEvent, fWhichWindow); }
  91.     virtual void DoDrag(void);
  92.     virtual void DoGoAway(void);                // handles setup, calls TDocument::DoClose
  93.  
  94.     // handlers you will need to override for functionality:
  95.     
  96.         // called by EventLoop and its handlers:
  97.         virtual void AdjustCursor(void) {}        // cursor adjust routine, should setup mouseRgn
  98.         virtual void DoMenuCommand(short menuID, short menuItem) {}
  99.         // called by OSEvent (just calls DoActivate by default, so no clip conversion
  100.         // is done). If you want to convert clipboard, override these routines
  101.         virtual void DoSuspend(Boolean doClipConvert);
  102.         virtual void DoResume(Boolean doClipConvert);
  103.     
  104.     // If you have an app that needs to know about these, override them
  105.     virtual void DoMouseUp(void) {}
  106.     virtual void DoDiskEvt(void) {}
  107.  
  108.     // Utility routines you need to provide to do MultiFinder stuff
  109.     virtual unsigned long SleepVal(void) { return 0; }        // how long to sleep in WaitNextEvent
  110.  
  111.     // useful variables
  112.     Boolean            fHaveWaitNextEvent;        // true if we have WaitNextEvent trap
  113.     Boolean            fDone;                    // set to true when we are ready to quit
  114.     EventRecord        fTheEvent;                // our event record
  115.     WindowPtr        fWhichWindow;            // currently active window
  116.     Boolean            fInBackground;            // true if our app is suspended
  117.     Boolean            fWantFrontClicks;        // true if we want front clicks
  118.     RgnHandle        fMouseRgn;                // mouse moved region (set it in your DoIdle)
  119.     TDocument*        fCurDoc;                // currently active document (if any)
  120.     TDocumentList*    fDocList;                // the list of documents
  121. };
  122.  
  123. // some other handy utility routines, not actually a part of application class
  124.  
  125. // display alert, using specified error STR# resource and error code as index
  126. void AlertUser(short errResID, short errCode);
  127. // call AlertUser to display error message, then quit...
  128. void BigBadError(short errResID, short errCode);
  129.  
  130. #endif
  131.